#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5,M=1e6+5;
const ll inf=1e15;
int n,a[N];
ll dp[N];
ll Mx[M],sum;
void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)dp[i]=-inf;
    for(int i=0;i<=1000000;i++)Mx[i]=-inf;
    dp[0]=Mx[0]=sum=0;
    for(int i=2;i<=n;i++){
        dp[i-1]=max(Mx[0]+sum,Mx[a[i]]+sum+a[i]);
        sum+=(a[i]==a[i-1]? a[i]:0);
        Mx[0]=max(Mx[0],dp[i-1]-sum);
        Mx[a[i-1]]=max(Mx[a[i-1]],dp[i-1]-sum);
    }
    ll ans=-inf;
    for(int i=0;i<n;i++)ans=max(ans,dp[i]);
    printf("%lld\n",ans);
    return;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)solve();
    return 0;
}